<?php

class Person_process extends CI_Model {//这里关于admin表的一些操作和登录判定

    const Statustrue = True;
    const Statusflase = False;

    function __construct() {
        parent::__construct();
          $this->load->helper('url');
           $this->load->library('file_upload'); //引入类库
    }

    function person_list() {
        $sql = "select * from person";
        $query = $this->db->query($sql);
        return $res = $query->result_array();
    }


    function add_person($post_array) {
        $post_array["desc"]=htmlspecialchars($post_array["desc"]);
        $insertsql = "insert into person(name,sex,jobs,
   photo,desciption,morder
)values(\"{$post_array["name"]}\",\"{$post_array["sex"]}\",\"{$post_array["jobs"]}\",
   \"{$post_array["full_path"]}\",   \"{$post_array["desc"]}\",\"{$post_array["order"]}\")";
    $this->db->query($insertsql);
    }
    function update_person($id) {
        $config['upload_path'] = './uploads/teamphoto'; //设定上传存储路径
        $data = $this->file_upload->upLoadfile($config, "photo");      
           if (isset($data)) {
            $siteurl = site_url(); //$siteurl .
            $config["source_image"] = $data["full_path"];
            $config["new_image"] = './uploads/teamphoto/thum';
            $this->file_upload->process_img($config);
            $post_array["full_path"] = "{$data["file_name"]}"; //获得新的图片名称对应数据库中banner字段            
            //同步更新数据库记录
            $_POST["desc"]=htmlspecialchars($_POST["desc"]);
        $update_sql = "update person set name=\"{$_POST["name"]}\",sex=\"{$_POST["sex"]}\",jobs=\"{$_POST["jobs"]}\",photo=\"{$post_array["full_path"]}\",desciption=\"{$_POST["desc"]}\",morder=\"{$_POST["order"]}\"
                where id=\"{$id}\"";
        } else {            
            //不更新图片链接，同步更新数据库
                 $_POST["desc"]=htmlspecialchars($_POST["desc"]);
      $update_sql = "update person set name=\"{$_POST["name"]}\",sex=\"{$_POST["sex"]}\",jobs=\"{$_POST["jobs"]}\",desciption=\"{$_POST["desc"]}\",morder=\"{$_POST["order"]}\"
                where id=\"{$id}\"";
        }
        $query = $this->db->query($update_sql);
        
    }
    

}

?>
